package org.csu.corp.controller.emp;

import org.csu.corp.entity.RespBean;
import org.csu.corp.entity.RespPageBean;
import org.csu.corp.entity.Sign;
import org.csu.corp.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee/clock")
public class EmpClockController {

    @Autowired
    private SignService signService;

    @GetMapping("/")
    public RespPageBean getSignByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, String workId) {
        return signService.getSignByPage(page, size, workId);
    }

    @PostMapping("/")
    public RespBean addSign(@RequestBody Sign record) {
        if (signService.sign(record) == 1) {
            return RespBean.ok("打卡成功!");
        }
        return RespBean.error("打卡失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteEmpByEid(@PathVariable Integer id) {
        if (signService.deleteSignById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @PutMapping("/")
    public RespBean updateEmp(@RequestBody Sign record) {
        if (signService.updateSign(record) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
}
